package lanou.giftsay_01.fragment.main;

import android.content.BroadcastReceiver;
import android.content.Intent;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.Toast;

import java.util.ArrayList;

import lanou.giftsay_01.adapter.Myadapter;
import lanou.giftsay_01.fragment.body.BoyfriendFragment;
import lanou.giftsay_01.fragment.body.SelectFragment;
import lanou.giftsay_01.main.guidemain.SearchMainActivity;
import lanou.giftsay_01.tools.BaseFragment;
import lanou.giftsay_01.R;

/**
 * Created by dllo on 16/8/15.
 */
public class GuideFragment extends BaseFragment {

    private ViewPager vp;
    private TabLayout tb;
    private Myadapter myadapter;
    private Spinner sp;
    private ArrayAdapter<String> arr_adapter ;
    private ImageView iv;

    @Override
    protected int setLayout() {
        return R.layout.guide_fragment;
    }

    @Override
    protected void initView() {
        iv = (ImageView) getView().findViewById(R.id.gift_search_guide);
        vp = (ViewPager) getView().findViewById(R.id.guide_vp);
        tb = (TabLayout) getView().findViewById(R.id.guide_tb);
        /**
         * 下拉菜单
         */
        sp = (Spinner) getView().findViewById(R.id.guide_sp);
        myadapter = new Myadapter(getChildFragmentManager());

      }

    @Override
    protected void initData() {
        ArrayList<String> name = new ArrayList<>();
        name.add("精选");
        name.add("送男票");
        name.add("海淘");
        name.add("创意生活");
        name.add("科技范");
        name.add("送爸妈");
        name.add("送基友");
        name.add("送闺蜜");
        name.add("送同事");
        name.add("送宝贝");
        name.add("设计感");
        name.add("文艺风");
        name.add("奇葩搞怪");
        name.add("萌萌哒");
      arr_adapter = new ArrayAdapter<String>(mContext ,android.R.layout.simple_spinner_item , name);
       arr_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        sp.setAdapter(arr_adapter);
        vp.setAdapter(myadapter);
        tb.setupWithViewPager(vp);
       sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
           @Override
           public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                 vp.setCurrentItem(position);
           }

           @Override
           public void onNothingSelected(AdapterView<?> parent) {

           }
       });
      iv.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Intent intent = new Intent( GuideFragment.this.getContext() , SearchMainActivity.class);
              startActivity(intent);
          }
      });
    }
}
